package leetcode;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * 描述:559. N 叉树的最大深度
 *
 * @author Madison You
 * @created 13:22
 */
public class Easy_559_MaxDepth {
    public static void main(String[] args) {

    }

    public int maxDepth(Node root) {
        Queue<Node> queue = new LinkedList<>();
        if (root == null) return 0;
        queue.offer(root);
        int deep = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            deep++;
            for (int i = 0; i < size; i++) {
                Node node = queue.poll();
                List<Node> children = node.children;
                if (children != null) {
                    for (Node child : children) {
                        queue.add(child);
                    }
                }
            }
        }
        return deep;
    }

    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }
}
